<template>
  <div>
    <el-dialog :title="''" :visible.sync="addEditIsDialog_c" @close="resetForm('formName')" width="110rem !important">
      <div class="main-content">
        <div class="left-content">
          <div class="title">
            <div>转入信息</div>
            <div class="el-icon-close title-close" @click="resetForm('formName')"></div>
          </div>
          <div class="line"></div>
          <div class="info">
            <div class="auto-box">
              <div class="item">{{ selectOutFishpondName }}</div>
              <div class="transfer">
                <div class="tilte">内部转移</div>
                <div class="arrow">
                  <div class="block"></div>
                </div>
              </div>
              <div class="item">{{ selectInFishpondName }}</div>
            </div>
          </div>
          <div class="number-box">
            <el-form :model="ruleForm" :rules="rules" ref="formName" class="demo-form-inline form">
              <el-form-item label="类型" prop="fishCode">
                <el-select v-model="ruleForm.fishCode" placeholder="请选择" clearable :popper-append-to-body="false">
                  <el-option v-for="item in fishTypesArray" :key="item.fishCode" :label="item.fishName" :value="item.fishCode"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="卵径" prop="diameter">
                <el-select v-model="ruleForm.diameter" placeholder="请选择" clearable :popper-append-to-body="false">
                  <el-option v-for="item in diametersArray" :key="item.id" :label="item.diameter" :value="item.diameter"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="数量" prop="num">
                <el-input v-model="ruleForm.num" placeholder="" clearable readonly show-word-limit></el-input>
              </el-form-item>
            </el-form>
          </div>
        </div>
        <div class="right-content">
          <div slot="footer" class="auto-box">
            <el-button class="btn hover1" v-for="(item, index) in numberArray" :key="index" @click="handleNumber(item)">{{ item }}</el-button>
            <el-button class="btn clear" @click="handleClear"></el-button>
            <el-button class="btn sure" type="primary" circle @click="submitForm('formName')">下一步</el-button>
          </div>
        </div>
      </div>
    </el-dialog>
    <Generation :generationIsDialog="generationIsDialog" :companyId="ruleForm.companyId" :baseId="ruleForm.baseId" :infosData="infosData" :calcNum="calcNum"></Generation>
  </div>
</template>
<script type="text/ecmascript-6">
import Generation from './generation'
import { getObjDiameters } from "@/api/breeding";
import { getObjFishTypes, getObjFishpondDetails, createTransferOrder } from "@/api/transfer";
export default {
  components: {
    Generation,
  },
  props: {
    companyId: {
      type: String,
      default: "",
    },
    baseId: {
      type: String,
      default: "",
    },
    outFishpondId: {
      type: String,
      default: "",
    },
    inFishpondId: {
      type: String,
      default: "",
    },
    selectOutFishpondName: {
      type: String,
      default: "",
    },
    selectInFishpondName: {
      type: String,
      default: "",
    },
    operationStatus: {
      type: Number,
      default: 0,
    },
    operationIsDialog: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      ruleForm: {
        // 表单字段
        companyId: "",
        baseId: "",
        outFishpondId: "",
        inFishpondId: "",
        fishCode: "",
        num: "",
        diameter: "",
      },
      rules: {
        // 表单规则
        fishCode: [
          { required: true, message: "请选择类型", trigger: "change" },
        ],
        diameter: [{ required: false, message: "请选择卵径", trigger: "change" }],
        num: [{ required: true, message: "请输入数量", trigger: "blur" }],
      },
      calcNum:'', // 计算数量
      ruleFormObj:{},
      fishTypesArray:[], // 鱼类型集合
      diametersArray: [], // 卵径集合
      addEditIsDialog_c: false, // 弹窗是否显示
      generationIsDialog: false,
      infosData:[], // 生成转移单详情
      numberArray:[7,8,9,4,5,6,1,2,3,0]
    };
  },
  watch: {
    operationIsDialog(val) {
      this.addEditIsDialog_c = val;
      if (this.addEditIsDialog_c) {
        this.ruleForm.companyId = this.companyId;
        this.ruleForm.baseId = this.baseId;
          this.ruleForm.outFishpondId = this.outFishpondId + "";
          this.ruleForm.inFishpondId = this.inFishpondId + "";
          this.getObjFishTypes();
          this.getObjDiameters();
      }
    },
  },
  methods: {
    // 输入
    handleNumber(val){
      if(this.ruleForm.num.length < 5){
        this.ruleForm.num += val +'';
      }
    },
    // 数字删除
    handleClear(){
      if(this.ruleForm.num != ''){
        // this.fishNumber = this.fishNumber.substring(0,this.fishNumber.length-1);
        this.ruleForm.num = '';
      }
    },
    // 取消
    resetForm(formName) {
      this.$refs[formName].resetFields();
      this.$parent.closeAddEdit();
    },
    // 孙组件调用
    closeSun(){
      this.$parent.closeAddEdit();
    },
    // 弹窗关闭
    closeAddEdit() {
      this.generationIsDialog = false;
    },
    // 获取排列表
    getObjFishTypes() {
      getObjFishTypes({id:this.companyId}).then((res) => {
        if (res.code == 200) {
          this.fishTypesArray = res.data;
        }
      });
    },
    // 获取卵径列表
    getObjDiameters() {
      getObjDiameters().then((res) => {
        if (res.code == 200) {
          this.diametersArray = res.data;
        }
      });
    },
    // 下一步
    submitForm(formName){
      this.$refs[formName].validate((valid) => {
        if (valid) {
          createTransferOrder(this.ruleForm).then((res) => {
            if (res.code == 200) {
              this.infosData = res.data;
              this.calcNum = this.ruleForm.num;
              this.generationIsDialog = true;
            }
          });
        }
      });
    }
  },
};
</script>

<style lang="less" scoped>
/deep/.el-dialog__header {
  background-color: transparent;
  padding: 0;
  position: relative;
  .el-dialog__title {
    color: white;
    font-size: 1.5rem !important;
  }
}
/deep/.el-dialog__body {
  padding: 0 !important;
}

.main-content {
  width: 100% !important;
  height: 40rem !important;
  display: flex;
  position: relative;
  .close {
    width: 3.29rem;
    height: 3.29rem;
    position: absolute;
    top: -5.29rem;
    right: 0;
    img {
      width: 100%;
      height: 100%;
    }
  }
}
.left-content {
  width: 70% !important;
  height: 40rem !important;
  background: #ffffff;
  .title {
    width: 94%;
    height: 15%;
    // border: 1px solid red;
    margin-left: 3.14rem;
    font-size: 2.84rem;
    font-family: PingFangSC-Regular, sans-serif;
    color: rgba(0, 0, 0, 0.85);
    font-weight: 900;
    display: flex;
    align-items: center;
    justify-content: space-between;
    .title-close {
      cursor: pointer;
    }
  }
  .line {
    height: 2px;
    width: 100%;
    background-color: #e8e8e8;
  }
  .info {
    width: 100%;
    height: 60%;
    display: flex;
    justify-content: center;
    align-items: center;
    .auto-box {
      width: 83%;
      height: 85%;
      // border: 1px solid red;
      display: flex;
      flex-flow: wrap;
      justify-content: space-between;
      align-content: space-around;
      .item {
        width: 11.5rem;
        height: 11.5rem;
        line-height: 11.5rem;
        margin-left: 2rem;
        margin-bottom: 2rem;
        color: #333333;
        font-size: 1.86rem;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 600;
        border-radius: 50%;
        border: 0.25rem solid #979797;
        text-align: center;
        cursor: pointer;
      }
      .transfer {
        display: flex;
        flex-direction: column;
        align-items: center;
        .tilte {
          height: 2.46rem;
          width: 8.44rem;
          text-align: center;
          line-height: 2.46rem;
          border-radius: 1.11rem;
          background-color: #ffd953;
          font-size: 1.86rem;
          font-family: PingFangSC-Medium, PingFang SC;
          font-weight: 600;
          color: rgba(0, 0, 0, 0.85);
        }
        .arrow {
          width: 13.57rem;
          height: 5.07rem;
          border-bottom: 0.27rem solid #979797;
          position: relative;
          .block {
            width: 3.5rem;
            height: 3.5rem;
            position: absolute;
            // bottom: 0.479rem;
            bottom: 7px;
            // right: -1.554rem;
            right: -23px;
            border-bottom: 0.27rem solid #979797;
            transform: rotate(45deg);
          }
        }
      }
    }
  }
  .number-box {
    width: 100%;
    height: 25%;
    display: flex;
    .form {
      width: 100%;
      // border: 1px solid red;
      display: flex;
      // align-items: center;
      justify-content: space-evenly;
      /deep/.el-form-item__content {
        display: flex;
        width: 18rem;
        // height: 5rem;
        line-height: 9.857143rem;
        .el-input__inner {
          height: 4.857143rem;
          font-size: 2.16rem;
        }
      }
      /deep/.el-form-item__label {
        font-size: 2.16rem;
        line-height: 9.857143rem;
      }
      /deep/.el-form-item__error {
        top: 40%;
        left: 5%;
      }
      ::v-deep .el-select-dropdown__empty {
        padding: 0.814286rem 3.3rem;
        font-size: 2rem;
      }
      ::v-deep .el-select-dropdown__list {
        .el-select-dropdown__item {
          font-size: 2rem;
          height: 4.428571rem;
          line-height: 4.428571rem;
        }
      }
    }
    .name {
      // width: 3.72rem;
      height: 2.26rem;
      font-size: 2.26rem;
      font-family: MicrosoftYaHei;
      color: #4f5a64;
      line-height: 2.26rem;
    }
    .input {
      margin-left: 0.79rem;
    }
    .next {
      width: 12rem;
      height: 5rem;
      font-size: 1.86rem;
    }
  }
}
.right-content {
  width: 30% !important;
  height: 40rem !important;
  background: #eeeeee;
  display: flex;
  justify-content: center;
  align-items: center;
  .auto-box {
    width: 90%;
    height: 85%;
    // border: 1px solid red;
    display: flex;
    flex-flow: wrap;
    justify-content: space-between;
    align-content: space-between;
    .btn {
      width: 7.43rem;
      height: 7.43rem;
      border-radius: 50%;
      box-shadow: 0rem 0.54rem 0.69rem 0rem rgba(163, 163, 163, 0.5);
      font-size: 2.9rem;
      font-weight: 600;
    }
    .clear {
      background-image: url(../../../../assets/transfer/clear.png);
      background-size: 3.93rem 3.93rem;
      background-position: center center;
      background-repeat: no-repeat;
    }
    .sure {
      width: 7.43rem;
      height: 7.43rem;
      border-radius: 50%;
      font-size: 1.86rem;
      box-shadow: 0rem 0.54rem 0.69rem 0rem rgba(163, 163, 163, 0.5);
    }
    .elBtn {
    }
  }
}
</style>
